package com.is.add.controller.restful;

import com.github.pagehelper.PageInfo;
import com.is.add.controller.vo.DepositBalanceVO;
import com.is.add.controller.vo.DepositPageListVO;
import com.is.add.controller.vo.DepositRecordVO;
import com.is.add.enmus.DepositOptTypeEnum;
import com.is.add.service.DepositService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 备用金查询模块
 */
@RestController
@RequestMapping("api/deposit")
@CrossOrigin
public class DepositController {
    @Autowired
    private DepositService depositService;
    /**
     * 备用金页选择项
     * @return  键值对list
     */
    @RequestMapping(value = "/depositList")
    public DepositPageListVO selectList(){
        return this.depositService.getDepositPageList();
    }

    /**
     * 备用金充值记录查询
     */
    @RequestMapping(value = "/rechargeRecord")
    public PageInfo<DepositRecordVO> rechargeRecord(@RequestParam String startTime,
                                                   @RequestParam String endTime,
                                                   @RequestParam(required = false) DepositOptTypeEnum optType,
                                                   @RequestParam(required = false) String searchKey,
                                                   @RequestParam(required = false,defaultValue = "1") int pageNum,
                                                   @RequestParam(required = false,defaultValue = "20") int pageSize){
        Map<String,Object> map =new HashMap<>();
        if (optType != null){
            map.put("optType",optType.getText());
        }
        if (searchKey != null){
            map.put("searchKey",searchKey);
        }
        map.put("startTime",startTime+" 00:00:00");
        map.put("endTime",endTime + " 23:59:59");
        return this.depositService.depositRechargeRecordQuery(map,pageNum,pageSize);
    }

    /**
     * 备用金余额查询
     */
    @RequestMapping(value = "/balance")
    public PageInfo<DepositBalanceVO> depositBalance(@RequestParam String endTime,
                                                     @RequestParam(required = false) Long depositType,
                                                     @RequestParam(required = false) String searchKey,
                                                     @RequestParam(required = false,defaultValue = "1") int pageNum,
                                                     @RequestParam(required = false,defaultValue = "20") int pageSize){
        Map<String,Object> map =new HashMap<>();
        if (depositType != null){
            map.put("depositType",depositType);
        }
        if (searchKey != null){
            map.put("searchKey",searchKey);
        }
        map.put("endTime",endTime);
        return this.depositService.balanceQuery(map,pageNum,pageSize);
    }

}
